<template>
  <el-dialog :visible="showAssignDialog" title="添加角色" @close="hClose">
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="item in enableList" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
    </el-checkbox-group>
    <el-row>
      <el-button type="primary" @click="hSave">确认</el-button>
      <el-button @click="hClose">取消</el-button>
    </el-row>
  </el-dialog>
</template>

<script>

import { getEmployeeDetail } from '@/api/employee'
import { getEnabledRoles } from '@/api/roles'
import { assignRoles } from '@/api/user'
export default {
  name: 'AssionRole',
  props: {
    showAssignDialog: {
      type: Boolean,
      required: true
    },
    currentId: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      checkList: [],
      //   roleIds: [],
      enableList: []
    }
  },
  async created() {
    await this.getEnable()
  },
  methods: {
    hClose() {
      this.$emit('update:showAssignDialog', false)
    },
    async getEnable() {
      const res = await getEnabledRoles()
      console.log(res)
      this.enableList = res.data
    },
    async getRoleIds() {
      const res = await getEmployeeDetail(this.currentId)
      console.log(res)
      this.checkList = res.data.roleIds
    },
    async hSave() {
      const res = await assignRoles({ id: this.currentId, roleIds: this.checkList })
      this.$message.success(res.message)
    }
  }
}
</script>

<style>

</style>
